package com.itheima.edu.info.manager.dao;
import com.itheima.edu.info.manager.domain.Student;
public class StudentDao {
    Student[] students = new Student[5];
    ;

    public boolean addStudent(Student student) {

        int index = -1;
        for (int i = 0; i < students.length; i++) {
            if (students[i] == null) {
                index = i;
                break;
            }
        }
        if (index == -1) {
            return false;

        } else {
            students[index] = student;
            return true;
        }
    }


    public Student[] findAllStudent() {
        return students;
    }

    public boolean deleteStudentById(String delid) {
        //查找id在容器中所在的索引位置
        int index=getIndex(delid);
        students[index]=null;
        return true;

    }

    //将该索引位置,使用null 元素进行覆盖
    public int getIndex(String id) {
        int index = -1;
        for (int i = 0; i < students.length; i++) {
            Student student = students[i];
            if (student != null && student.getId().equals(id)) {
                index = i;
                break;
            }
        }
        return index;
    }
}


